/*
 * ReportesForm.java
 *
 * Created on June 18, 2008, 10:04 AM
 */

package View;

import Controller.ReportesController;
import javax.swing.UIManager;
import com.birosoft.liquid.*;
import Model.Congreso;
import Model.Detalle;
import Model.VentasXCongreso;
import Model.VentasXMes;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  Gigin
 */
public class ReportesForm extends javax.swing.JFrame {

   // Controller del Form
    //tabla base para dibujar la tabla de pedidos
    private DefaultTableModel tablaBase;
    private Congreso congreso;
    private ReportesController rCon;

  //Para manejar pantallas
    private PpalForm ppal; 
    private String modo;
    
    /** Creates new form ReportesForm */
    public ReportesForm(String modo, Congreso cong) {
               
        this.setModo(modo);
        this.setCongreso(cong);
        
        //Se crea el controller de la pantalla
        rCon = new ReportesController();
        
        // Se carga el Look and Feel
        try {
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");   
        } catch (Exception e) { }
          LiquidLookAndFeel.setStipples(false);
          LiquidLookAndFeel.setShowTableGrids(true);
        initComponents();

        
        
        
    }

   //*se crea la tabla de pedidos en pantalla*/ 
private void buildTableCongresos(){
        tablaBase  = new DefaultTableModel(){
                      public boolean isCellEditable(int row, int column) { return false;}
         };
         
         
         tablaBase.addColumn("Congreso");
         tablaBase.addColumn("Fecha");
         tablaBase.addColumn("Finalización");
         tablaBase.addColumn("Pedidos");
         tablaBase.addColumn("Cantidad DVD");
         tablaBase.addColumn("Total Ventas");
         tablaBase.addColumn("Total Gastos");
         tablaBase.addColumn("Saldo");
         tabItems.setModel(tablaBase);
        Vector tmp;
        ArrayList<VentasXCongreso> congresos = rCon.getCongresos();
        
        
        
        for (int i=0; i<congresos.size();i++)
        {
          String diaI = congresos.get(i).getCongreso().getFechaInicio().substring(8, 10);  
          String mesI = congresos.get(i).getCongreso().getFechaInicio().substring(5, 7);
          String anioI = congresos.get(i).getCongreso().getFechaInicio().substring(0, 4);
          String fechaI = diaI+"/"+mesI+"/"+anioI;
            
          String diaF = congresos.get(i).getCongreso().getFechaFin().substring(8, 10);  
          String mesF = congresos.get(i).getCongreso().getFechaFin().substring(5, 7);
          String anioF = congresos.get(i).getCongreso().getFechaFin().substring(0, 4);
          String fechaF = diaF+"/"+mesF+"/"+anioF;
          
          tmp= new Vector();
          tmp.add(congresos.get(i).getCongreso().getIniciales());
          tmp.add(fechaI);
          tmp.add(fechaF);          
          tmp.add(congresos.get(i).getcantidadPedidos());
          tmp.add(congresos.get(i).getcantidadDVD());
          tmp.add("$ "+congresos.get(i).gettotalVendido());
          tmp.add("$ "+congresos.get(i).gettotalGastado()); 
          tmp.add("$ "+congresos.get(i).getSaldo()); 
          tablaBase.addRow(tmp);
          }
            
         tabItems.setModel(tablaBase);
                
    }

private void buildTableMeses(){
        tablaBase  = new DefaultTableModel(){
                      public boolean isCellEditable(int row, int column) { return false;}
         };
         
         
         tablaBase.addColumn("Año");
         tablaBase.addColumn("Mes");
         tablaBase.addColumn("Pedidos");
         tablaBase.addColumn("Cantidad DVD");
         tablaBase.addColumn("Total Ventas");
         tablaBase.addColumn("Total Gastos");
         tabItems.setModel(tablaBase);
        Vector tmp;
        ArrayList<VentasXMes> meses = rCon.getMeses();
        
      for (int i=0; i<meses.size();i++)
        {
          tmp= new Vector();
          tmp.add(meses.get(i).getAnio());
          tmp.add(meses.get(i).getMes());      
          tmp.add(meses.get(i).getCantidadPedidos());
          tmp.add(meses.get(i).getCantidadDVD());
          tmp.add("$ "+meses.get(i).getTotalVendido());
          tmp.add("$ "+meses.get(i).getTotalGastado()); 
          tablaBase.addRow(tmp);
          }
            
         tabItems.setModel(tablaBase);
                
    }
   
private void buildTableClientes(){
        tablaBase  = new DefaultTableModel(){
                      public boolean isCellEditable(int row, int column) { return false;}
         };
         
         
         tablaBase.addColumn("Nombre");
         tablaBase.addColumn("Documento");
         tablaBase.addColumn("Localidad");
         tablaBase.addColumn("País");
         tablaBase.addColumn("Cantidad DVD");
         tablaBase.addColumn("Total");
         tablaBase.addColumn("Primera Compra");
         tabItems.setModel(tablaBase);

        Vector tmp;
        ArrayList<Detalle> clientes = rCon.getClientes();
        
      for (int i=0; i<clientes.size();i++)
        {
          String diaI = clientes.get(i).getFechaInicial().substring(8, 10);  
          String mesI = clientes.get(i).getFechaInicial().substring(5, 7);
          String anioI = clientes.get(i).getFechaInicial().substring(0, 4);
          String fechaI = diaI+"/"+mesI+"/"+anioI;
          
          
          tmp= new Vector();
          tmp.add(clientes.get(i).getCliente().getApellidoCli()+" "+clientes.get(i).getCliente().getNombreCli());
          tmp.add(clientes.get(i).getCliente().getNroDocumento());
          tmp.add(clientes.get(i).getCliente().getLocalidad());          
          tmp.add(clientes.get(i).getCliente().getPais());
          tmp.add(clientes.get(i).getCantidad());
          tmp.add("$ "+clientes.get(i).getTotalGastado());
          tmp.add(fechaI);        
          tablaBase.addRow(tmp);
          }
            
         tabItems.setModel(tablaBase);
                
    }
    
    /** Se cargan los valores de los Jtextfields de la pantalla*/

    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabelCiudad = new javax.swing.JLabel();
        jButtonClientes1 = new javax.swing.JButton();
        jButtonMes = new javax.swing.JButton();
        jButtonCongreso = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabItems = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 1, 24));
        jLabel1.setForeground(new java.awt.Color(94, 148, 189));
        jLabel1.setText("Seleccione el reporte deseado");

        jLabelCiudad.setFont(new java.awt.Font("Verdana", 0, 10));

        jButtonClientes1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes3_normal.gif"))); // NOI18N
        jButtonClientes1.setToolTipText("Ver datos de todos los clientes");
        jButtonClientes1.setBorderPainted(false);
        jButtonClientes1.setContentAreaFilled(false);
        jButtonClientes1.setFocusPainted(false);
        jButtonClientes1.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes3_presionado.gif"))); // NOI18N
        jButtonClientes1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes3_mouse.gif"))); // NOI18N
        jButtonClientes1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClientes1ActionPerformed(evt);
            }
        });

        jButtonMes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes2_normal.gif"))); // NOI18N
        jButtonMes.setToolTipText("Ver info de las ventas realizadas por mes");
        jButtonMes.setBorderPainted(false);
        jButtonMes.setContentAreaFilled(false);
        jButtonMes.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes2_presionado.gif"))); // NOI18N
        jButtonMes.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes2_mouse.gif"))); // NOI18N
        jButtonMes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMesActionPerformed(evt);
            }
        });

        jButtonCongreso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes1_normal.gif"))); // NOI18N
        jButtonCongreso.setToolTipText("Ver info de las ventas realizadas por congreso");
        jButtonCongreso.setBorderPainted(false);
        jButtonCongreso.setContentAreaFilled(false);
        jButtonCongreso.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes1_presionado.gif"))); // NOI18N
        jButtonCongreso.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Reportes1_mouse.gif"))); // NOI18N
        jButtonCongreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCongresoActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/logo_GTV4.gif"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(712, 712, 712)
                        .addComponent(jLabelCiudad))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(80, 80, 80)
                                .addComponent(jButtonClientes1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonMes, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26)
                                .addComponent(jButtonCongreso, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(116, 116, 116)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(164, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(jButtonClientes1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButtonCongreso, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonMes, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabelCiudad)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CAJA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 1, 12), new java.awt.Color(94, 148, 189))); // NOI18N

        jLabel7.setFont(new java.awt.Font("Verdana", 1, 10));
        jLabel7.setForeground(new java.awt.Color(94, 148, 189));
        jLabel7.setText("Reporte");

        jScrollPane1.setFont(new java.awt.Font("Verdana", 0, 10)); // NOI18N

        tabItems.setFont(new java.awt.Font("Verdana", 0, 10));
        tabItems.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Número Pedido", "Cliente", "Total"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tabItems);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Volver_normal.gif"))); // NOI18N
        jButton1.setToolTipText("Volver a la pantalla principal");
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Volver_deshabilitado.gif"))); // NOI18N
        jButton1.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Volver_presionado.gif"))); // NOI18N
        jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Volver_mouse.gif"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 840, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(687, 687, 687)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.getAccessibleContext().setAccessibleName("REPORTE");

        pack();
    }// </editor-fold>//GEN-END:initComponents

/** Acciones cuando se presiona el boton "Modificar saldo"*/
private void jButtonCongresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCongresoActionPerformed
    buildTableCongresos();
}//GEN-LAST:event_jButtonCongresoActionPerformed

private void jButtonClientes1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClientes1ActionPerformed
   
/*    ReportesExcelForm iForm = new ReportesExcelForm(this, true);

    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    iForm.setLocation(screenWidth / 4, screenHeight / 4);
    iForm.setVisible(true);  */
}//GEN-LAST:event_jButtonClientes1ActionPerformed

private void jButtonMesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMesActionPerformed
    buildTableMeses();
}//GEN-LAST:event_jButtonMesActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
ppal.cargarFormulario();
this.dispose();

    // TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed



public Congreso getCongreso(){
        return congreso;
    }
    
    public void setCongreso(Congreso val){
        this.congreso = val;
    } 


public String getModo() {
        return modo;
    }
    
public void setModo (String val) {
        this.modo = val;
    }

public void setPpal(PpalForm p){
       this.ppal=p;
}


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonClientes1;
    private javax.swing.JButton jButtonCongreso;
    private javax.swing.JButton jButtonMes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelCiudad;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabItems;
    // End of variables declaration//GEN-END:variables

}
